﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Project
{
    public partial class option : Form
    {
        public option()
        {
            InitializeComponent();
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {

            int error = 0;


            if (cblogin.Checked)
            {
                Properties.Settings.Default.textbox = "ASD";
            }
            else
                Properties.Settings.Default.textbox = "Main";

            if (txtNotification.Text != "")
            {
                Properties.Settings.Default.notificationDays = Convert.ToInt16(txtNotification.Text);
                error = 0;
            }
            else
                error = 1;

            if (error == 0)
            {
                Properties.Settings.Default.Save();
                this.Close();
            }
            else
            {
                MessageBox.Show("Please enter number of days to generate notifications at start");
                txtNotification.BackColor = Color.AntiqueWhite;
            }

        }

        private void option_Load(object sender, EventArgs e)
        {
            string checker = Properties.Settings.Default.textbox.ToString();


            if (checker != "Main")
            {
                cblogin.Checked = true;
            }
            else
            {
                cblogin.Checked = false;
            }
            txtNotification.Text = Properties.Settings.Default.notificationDays.ToString();


            lblDatabasePath.Text = Properties.Settings.Default.database.ToString();


        }

        private void button2_Click(object sender, EventArgs e)
        {
            string currentpass;


            currentpass = Properties.Settings.Default.pass.ToString();





            if (txtpass1.Text == "")
            {
                txtpass1.BackColor = Color.AntiqueWhite;
            }
            if (txtpass2.Text == "")
            {
                txtpass2.BackColor = Color.AntiqueWhite;
            }


            if (txtoldpass.Text != "")
            {
                txtoldpass.BackColor = Color.White;
            }
            if (txtpass1.Text != "")
            {
                txtpass1.BackColor = Color.White;
            }
            if (txtpass2.Text != "")
            {
                txtpass2.BackColor = Color.White;
            }


            if (txtoldpass.Text == "")
            {
                txtoldpass.BackColor = Color.AntiqueWhite;
            }
            else
            {

                if (txtoldpass.Text != currentpass)
                {
                    MessageBox.Show("Error: Current Password is wrong.");
                }
                else
                {
                    if (txtpass1.Text != txtpass2.Text)
                    {
                        MessageBox.Show("Password does not match");

                        txtpass1.BackColor = txtpass2.BackColor = Color.AntiqueWhite;
                    }
                    else
                    {
                        if (txtpass1.Text != "")
                        {
                            Properties.Settings.Default.pass = txtpass1.Text;
                            txtpass1.BackColor = txtpass2.BackColor = Color.White;
                            txtoldpass.Text = "";
                            txtpass1.Text = "";
                            txtpass2.Text = "";
                            MessageBox.Show("Password changed successfully.");
                            Properties.Settings.Default.Save();
                        }
                    }


                }
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Properties.Settings.Default.pass = "1";
            Properties.Settings.Default.Save();
        }

        private void button3_Click_1(object sender, EventArgs e)
        {
           
                OpenFileDialog o = new OpenFileDialog();
                o.Filter = "Database File (*.mdb)|*.mdb";


                o.ShowDialog();

                if (o.FileName.ToString() != "")
                {

                    DialogResult dialogResult = MessageBox.Show("Connect to database: " + o.FileName.ToString(), "", MessageBoxButtons.YesNo);

                    if (dialogResult == DialogResult.Yes)
                    {
                        string setLocation = o.FileName.ToString();
                        Properties.Settings.Default.database = setLocation;
                    }
                    else if (dialogResult == DialogResult.No)
                    {
                        //
                    }
                }
                Properties.Settings.Default.Save();
                lblDatabasePath.Text = Properties.Settings.Default.database.ToString();


                Main result = new Main();
               
            
        }
    }
    }

